package com.kou.dao;

import com.kou.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author SteinY
 * @create 2022-03-28 10:38
 * @description:
 */
public class GoodsTypeDaoImpl implements GoodsTypeDao {
    QueryRunner queryRunner = new QueryRunner();
    @Override
    public String findParentName(Integer parent) {
        Connection connection = DataSourceUtil.getConnection();
        String sql ="select name from tb_goods_type where id = ? ";
        try {
           return (String) queryRunner.query(connection,sql,new ScalarHandler(),parent);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String findTypeName(int id) {
        Connection connection = DataSourceUtil.getConnection();
        String sql ="select name from tb_goods_type where id = ? ";
        try {
            return (String) queryRunner.query(connection,sql,new ScalarHandler(),id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
